﻿<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<TemplateWeb.Models.ViewModels.GroupViewModel>" %>

<script type="text/javascript">
    $(function () {
        // Document.ready -> link up remove event handler 
        $(".RemoveLink").click(function () {
            // Get the id from the link 
            var recordToDelete = $(this).attr("data-id");

            if (recordToDelete != '') {

                // Perform the ajax post 
                $.post("/Home/RemoveFromCart", { "id": recordToDelete },
                function (data) {
                    // Successful requests get here 
                    // Update the page elements 
                    $('#row-' + data.DeleteId).fadeOut('slow');
                    if (data.CartTotal == 0) {
                        location.href = "/Home";
                    } else {
                        $('#cart-total').text(formatMoney(data.CartTotal, "", 3, 0) + " Đ");
                    }
                });
            }
        });

    });

    function handleUpdate() {
        // Load and deserialize the returned JSON data 
        var json = context.get_data();
        var data = Sys.Serialization.JavaScriptSerializer.deserialize(json);

        // Update the page elements 
        $('#row-' + data.DeleteId).fadeOut('slow');
        $('#cart-total').text(formatMoney(data.CartTotal, "", 3, 0) + " Đ");
    }

    function formatMoney(theNumber, theCurrency, theThousands, theDecimal) {
        var theDecimalDigits = Math.round((theNumber * 100) - (Math.floor(theNumber) * 100));
        theDecimalDigits = "" + (theDecimalDigits + "0").substring(0, 2);
        theNumber = "" + Math.floor(theNumber);
        var theOutput = theCurrency;
        for (x = 0; x < theNumber.length; x++) {
            theOutput += theNumber.substring(x, x + 1);
            if (isThousands(theNumber.length - x - 1) && (theNumber.length - x - 1 != 0)) {
                theOutput += theThousands;
            };
        };
        theOutput += theDecimal + theDecimalDigits;
        return theOutput;
    };
</script> 

<div class="box_side">
    <div class="side_title" style="color:#D3610A;">Hỗ trợ trực tuyến</div>
    <table width="100%" border="0" cellpadding="5" cellspacing="5">
		<tr>
            <td style="text-align:center;">
                <a href="ymsgr:sendIM?jedi_t07">
                    <img title="Hỗ trợ" alt="Hỗ trợ" src="http://opi.yahoo.com/online?u=jedi_t07&m=g&t=2" border="0"/>
                </a>
            </td>
        </tr>
        <tr>
            <td style="text-align:center;">
                <div style="padding-left:5px;">
                    <span style="color:#6f52aa;">Hỗ trợ: sy tuan</span>
                </div>
            </td>
        </tr>
        <tr>
            <td style="text-align:center;">
                <div style="padding-left:5px;">
                    <span style="color:#6f52aa;">Phone: 01234567890</span>
                </div>
            </td>
        </tr>
    </table>
</div>

<% using (Html.BeginForm("TimKiem", "Home", FormMethod.Post))
   { %>
<div class="box_side">
    <div class="side_title" style="color:#D3610A;">Tìm kiếm</div>
	<table width="100%" border="0" cellpadding="5" cellspacing="5">
	    <tbody>
            <tr>
                <td>
                    Tên sách                    
                </td>      
            </tr>
            <tr>
                <td>
                     <input name="txtTimKiemTenSach" type="text" style="width:205px;" />                   
                </td>      
            </tr>   
            <tr>
                <td>
                    Tên tác giả                 
                </td>      
            </tr>
            <tr>
                <td>
                     <input name="txtTimKiemTenTacGia" type="text" style="width:205px;" />                   
                </td>      
            </tr> 
            <tr>
                <td style="float: right; padding-right: 20px;">
                    <input type="submit" name="sbt" id="Submit1" value="Tìm kiếm" style="background-image: url(../../../Content/Images/Home/bgbutton.jpg); color: #FFFFFF; font-size: 16px; font-weight: bold; border: 1px #DBDBDB solid; height: 30px; cursor:pointer;" />
                </td>
            </tr>   
	    </tbody>
    </table>
    <div style="clear:both"><img src="../../../Content/Images/Home/horz_sep.png" width="280" height="1" class="horz_div"></div>
</div>		
<% } %>
<div class="box_side">
    <div style="clear:both"><img src="../../../Content/Images/Home/RHS_Top.jpg" width="233" height="45" alt="Shop Online Now!"></div>
    <div id="RHS_WaysToShop">
        <div class="container">              
            <div>
                <div class="pointer"></div>
                <div class="text">
                    <div>
                        <div style="float:left">Giỏ hàng / Thanh toán</div>
                        <div style="float:left; padding-left:5px"><img src="../../../Content/Images/Home/cart_img.png" alt="View Your Cart / Check Out" title="View Your Cart / Check Out" /></div>
                    </div>
                    <!--DYNSTART-->
                        
                    <div id="cart_section_top" style="clear:both;">
                        <table border="0" width="100%" cellspacing="0" cellpadding="0">
                            <% 
                                var cartIsEmpty = true;
                                if (Model.ShoppingCartModel != null && Model.ShoppingCartModel.CartItems != null && Model.ShoppingCartModel.CartItems.Count > 0)
                                {
                                    cartIsEmpty = false;
                                } 
                            %>
                            <% if (cartIsEmpty)
                                { %>
                                <tr>
                                    <td>
                                        <div style="color:Blue; padding-left: 18px;">Chưa có sản phẩm!</div>
                                    </td>
                                </tr>
                            <% }
                                else
                                { %>
                                <tr style="border-top: 1px dotted #ddd;">
                                    <td colspan="4" style="height:5px;"></td>
                                </tr>
                                <% for (int i = 0; i < Model.ShoppingCartModel.CartItems.Count; i++ )
                                    { %>
                                    <tr id="row-<%= Model.ShoppingCartModel.CartItems[i].RecordId %>"> 
                                        <td style="text-align:left;">
                                            <%
                                                var item = Model.AllSachModel.GetModel.LstObjModel.FirstOrDefault(n => n.ID == Model.ShoppingCartModel.CartItems[i].SachID);
                                                %>
                                            <%= i+1 %> - <%= item.TenSach%>
                                        </td>
                                        <td style="width:20px; text-align:center; padding-left: 5px;">
                                            <script type="text/javascript">
                                                function ReCalcOrder(itemid, idcate) {
                                                    var num = document.getElementsByName("NumItem" + itemid).item(0);
                                                    if (!isNaN(num.value) && parseInt(num.value) > 0) {
                                                        window.location.href = "../Home/AddToCart?id=" + itemid + "&idloaisach=" + idcate + "&num=" + num.value;
                                                    } else {
                                                        window.location.href = "../Home/AddToCart?id=" + itemid + "&idloaisach=" + idcate + "&num=" + <%= Model.ShoppingCartModel.CartItems[i].Count %>;
                                                    }
                                                    
                                                }
                                            </script>
                                            <input type="text" name="NumItem<%= item.ID %>" id="item-count-<%= Model.ShoppingCartModel.CartItems[i].RecordId %>" value="<%= Model.ShoppingCartModel.CartItems[i].Count %>" style="width:15px;font-size:10px;text-align:center;" maxlength="2" onkeyup='ReCalcOrder(<%= item.ID %>, <%= item.IDLoaiSach %>);'>
                                        </td>
                                        <td style="width:60px;text-align:right;padding-right:5px;"><%= string.Format("{0:0,0}", item.Gia)%> Đ</td>
                                        <td style="width:12px;">
                                            <a href="#" title="Remove from cart" class="RemoveLink" data-id="<%= Model.ShoppingCartModel.CartItems[i].RecordId %>">
                                                <img src="../../../Content/Images/Home/delete.gif" alt="Remove From Cart" border="0" />
                                            </a>
                                        </td>
                                    </tr>
                                <% } %>
                                <tr style="border-top: 1px dotted #ddd;">
                                    <td style="padding-left: 4px; padding-top: 15px; color: Blue;">Thành tiền</td>
                                    <td id="cart-total" colspan="2" style="text-align:right;padding-right:5px;font-weight:bold;  padding-top: 15px;">
                                        <%= string.Format("{0:0,0}", Model.ShoppingCartModel.CartTotal) %> Đ
                                    </td>
                                    <td style="padding-top: 15px;">
                                        <a href="#" title="Empty Cart">
                                        </a>
                                    </td>
                                </tr>
                                <tr>
                                    <td colspan="4" style="height:10px;"></td>
                                </tr>
                                <tr>
                                    <td colspan="4" align="center">
                                        <% using (Html.BeginForm("Approve", "Home", FormMethod.Post))
                                            { %>
                                            <p style="text-align:left; margin-bottom: 5px; padding-left: 35px;">
                                                <input name="totalpay" type="hidden" value="<%= Model.ShoppingCartModel.CartTotal %>" />
                                                <input type="submit" name="sbt" id="sbt" value="Thanh toán" style="background-image: url(../../../Content/Images/Home/bgbutton.jpg); color: #FFFFFF; font-size: 16px; font-weight: bold; border: 1px #DBDBDB solid; height: 30px; cursor:pointer;" />
                                            </p>
                                        <% } %>
                                    </td>
                                </tr>
                            <% } %>
                        </table><!-- End   - put your content here --->
                    </div>
                    <!--DYNEND-->
                </div>
            </div>
            <!--DYNSTART-->
            <div style="clear:both"><img src="../../../Content/Images/Home/horz_sep.png" width="280" height="1" class="horz_div"/></div>               
            <div>
                <div class="pointer"></div>
                <div class="text">
                    <div style="clear:both">
                        <!-- User has loged in -->
                        <% if (Request.IsAuthenticated)
                            { %>
                            <div style="float:left">
                                Hi, <a href="<%= Url.Action("ThongTinNguoiDung", "Account", new { username = Page.User.Identity.Name }) %>" id="A2"><span style="color: Red;"><%= Page.User.Identity.Name %></span></a>
                            </div>
                            <% if ("SUPERADMIN".Equals(Roles.GetRolesForUser(Page.User.Identity.Name)[0].ToUpper()) ||
                                   "ADMIN".Equals(Roles.GetRolesForUser(Page.User.Identity.Name)[0].ToUpper()))
                                { %>
                                <div style="float:left; padding: 0 5px 0 5px">|</div>
                            <% }
                                else
                                { %>
                                <div style="float:left; padding: 0 5px 0 5px">|</div>
                            <% } %>
                            <div style="float:left">
                                <a href="<%= Url.Action("LogOff", "Account") %>" id="A1">Đăng xuất</a>
                            </div>
                        <% }
                            else
                            { %>
                            <div style="float:left">
                                <a href="<%= Url.Action("Login", "Home") %>" id="loginOrLogoutLink">Đăng nhập</a>
                            </div>
                            <div style="float:left; padding: 0 20px 0 20px">|</div>
                            <div style="float:left">
                                <a href="<%= Url.Action("Register", "Account") %>" id="NewRegistLink">Đăng ký</a>
                            </div>
                        <% } %>
                    </div>
                </div>
            </div>

            <!--DYNSTART-->
         <% if (!Request.IsAuthenticated)
            { %>
            <div>
                <div class="pointer"></div>
                <div class="text">
                    <div style="clear:both">
                        <div style="float:left">
                            <a href="<%= Url.Action("ResetPassword", "Account") %>" id="A3">Quên mật khẩu</a>
                        </div>
                    <//div>
                </div>
            </div>
        <% } %>

            <!-- User has loged in -->
        <% if (Request.IsAuthenticated)
            { %>
                <div>
                    <div class="pointer"></div>
                    <div class="text">
                        <div style="clear:both">
                            <div style="float:left">
                                <a href="<%= Url.Action("ChangePassword", "Account") %>" id="A5">Đổi mật khẩu</a>
                            </div>     
                        </div>
                    </div>
                </div>   
                <div>
                    <div class="pointer"></div>
                    <div class="text">
                        <div style="clear:both">
                            <div style="float:left">
                                <a href="<%= Url.Action("OrdersHistory", "Home", new { username = Page.User.Identity.Name }) %>" id="A4">Lịch sử giao dịch</a>
                            </div>     
                        </div>
                    </div>
                </div>      
         <% } %>

            <!-- User has loged in -->
        <% if (Request.IsAuthenticated)
            { %>
            <% if ("SUPERADMIN".Equals(Roles.GetRolesForUser(Page.User.Identity.Name)[0].ToUpper()) ||
                        "ADMIN".Equals(Roles.GetRolesForUser(Page.User.Identity.Name)[0].ToUpper()))
                { %>
                <div>
                    <div class="pointer"></div>
                    <div class="text">
                        <div style="clear:both">
                            <div style="float:left; padding: 0 5px 0 5px"></div>
                            <div style="float:left">
                                <a href="<%= Url.Action("Index", "Admin") %>" id="A7">Vào trang quản trị</a>
                            </div>
                        </div>
                    </div>
                </div>
             <% } %>
         <% } %>
            <!--DYNEND-->
        </div>
    </div>
</div>
<div class="hot_product">
    <link rel="stylesheet" media="screen" type="text/css" href="../../../Content/HomeCSS/ImageOverlay.css" />
    <script type="text/javascript" src="../../../Scripts/jquery.metadata.js"></script>
	<script type="text/javascript" src="../../../Scripts/jquery.ImageOverlay.js"></script>
    <ul id="thirdGallery" class="image-overlay { overlay_speed: 'slow' }">
        <% foreach (var item in Model.SachBestSellerModel.GetModel.LstObjModel)
           {%>
                <li>
			        <a href="<%= Url.Action("ChiTietSach", "Home", new { id = item.ID }) %>" class="{ overlay_speed: &#39;fast&#39;, overlay_speed_out: &#39;slow&#39; }" style="width: 0px; height: 0px; border-top-color: rgb(102, 102, 102); border-right-color: rgb(102, 102, 102); border-bottom-color: rgb(102, 102, 102); border-left-color: rgb(102, 102, 102); ">
				        <img alt="<%= item.TenSach %>" src="../../../Content/Images/Items/<%= item.HinhMinhHoa %>" width="230" height="320" title=""/>
				        <div class="caption" style="background-color: rgb(0, 0, 0); color: rgb(102, 102, 102); top: 320px; ">
					        <h3><%= item.TenSach %></h3>
					        <p></p><p><span style="color: rgb(255, 102, 0); "><strong></strong></span><%= Html.Truncate(item.NoiDungRutGon, WebConfiguration.SachSortDescription) %></p><p></p>
				        </div>
			        </a>
		        </li>
            <% 
           } %>
    </ul>
    <p style="clear: both; height: 0;">&nbsp;</p>
    <script type="text/javascript">
        // JavaScript for the Image Overlay galleries.
        $("#thirdGallery").ImageOverlay();
	</script>
    <div class="title">&nbsp;&nbsp;Bestseller</div>
</div>		
<div class="box_side">
    <div class="side_title">Tin mới cập nhật <img src="../../../Content/Images/Home/new.gif" alt=""></div>
	<table width="100%" border="0" cellpadding="5" cellspacing="5">
	    <tbody>
        <% foreach (var item in Model.TinTucNewestModel.GetModel.LstObjModel.Take(5))
            { %>
            <tr>
			    <td align="center" valign="top" width="8">
                    <img src="../../../Content/Images/Home/icon1.png" width="4" height="7" border="0" style="margin-top:7px;">
                </td>
			    <td valign="top">
                    <a href="<%= Url.Action("ChiTietTinTuc", "Home", new { id = item.ID }) %>" title="<%= item.TieuDe %>"><%= item.TieuDe %></a>
                </td>
		    </tr>   
         <% } %>       
	    </tbody>
    </table>
</div>			
<div class="danhngon">
	<table align="center" width="90%" cellspacing="0" cellpadding="5" border="0">
		<tbody>
            <tr><td><h1>Mỗi ngày một danh ngôn</h1></td></tr>
		    <tr><td>&nbsp;</td></tr>
		    <tr><td><p><b><i>Lòng nhiệt tình là nguồn tài sản lớn nhất thế giới, nó đánh bại tiền bạc, quyền lực và tầm ảnh hưởng!</i></b></p>
            <p>(Trích<em> PQ - &nbsp;Chỉ số đam mê</em>)</p></td></tr>
	    </tbody>
    </table>
</div>		
